package com.developer.loginsample.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.developer.loginsample.R;
import com.developer.loginsample.util.Util;
import com.parse.ParseUser;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		ParseUser parseUser = ParseUser.getCurrentUser();
		if (parseUser == null) {
			Util.redirectActivity(this, LoginActivity.class);
		} else {
			Util.showMessage(this, "Welcome " + parseUser.getUsername());
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main_menu, menu);
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
			case R.id.menu_logout:
				ParseUser.logOut();
				Util.redirectActivity(this, LoginActivity.class);
				break;
		}
		return super.onOptionsItemSelected(item);
	}

}
